/*
 * This file is part of aion-unique <aion-unique.org>.
 *
 *  aion-unique is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  aion-unique is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with aion-unique.  If not, see <http://www.gnu.org/licenses/>.
 */
package com.aionemu.gameserver.model.team.legion;

import com.aionemu.gameserver.model.gameobjects.PersistentState;

/**
 * @author Simple
 * 
 */
public class LegionEmblem
{
	private byte			version		= 0x00;
	private boolean			userEmblem  = false;
	private int				color_rgb		= 0x000000FF;
	private boolean			defaultEmblem	= true;
	private PersistentState	persistentState;

	private boolean			isUploading		= false;
	private int				uploadSize		= 0;
	private int				uploadedIndex	= 0;
	private byte[]			uploadData;

	public LegionEmblem()
	{
		setPersistentState(PersistentState.NEW);
	}

	
	/**
	 * @param emblemId
	 *            the emblemId to set
	 * @param color_rgb
	 *            the color_rgb to set
	 */
	public void setEmblem(byte version, boolean isUserEmblem, int color_rgb)
	{
		this.version = version;
		this.userEmblem = isUserEmblem;
		this.color_rgb = color_rgb;
		setPersistentState(PersistentState.UPDATE_REQUIRED);
		this.defaultEmblem = false;
		this.uploadData = new byte[0];
	}

	/**
	 * @return the emblemId
	 */
	public byte getVersion()
	{
		return version;
	}

	/**
	 * @return the emblemId
	 */
	public void setVersion(byte version)
	{
		this.version = version;
	}

	/**
	 * @return the color_r
	 */
	public int getColor_rgb()
	{
		return color_rgb;
	}

	/**
	 * @return the color_r
	 */
	public void setColor_rgb(int color)
	{
		color_rgb = color;
	}

	/**
	 * @return the defaultEmblem
	 */
	public boolean isDefaultEmblem()
	{
		return defaultEmblem;
	}

	/**
	 * @param isUploading
	 *            the isUploading to set
	 */
	public void setUploading(boolean isUploading)
	{
		this.isUploading = isUploading;
	}

	/**
	 * @return the isUploading
	 */
	public boolean isUploading()
	{
		return isUploading;
	}

	/**
	 * @return Returns the userEmblem.
	 */
	public boolean isUserEmblem()
	{
		return userEmblem;
	}


	/**
	 * @param userEmblem The userEmblem to set.
	 */
	public void setUserEmblem(boolean userEmblem)
	{
		this.userEmblem = userEmblem;
	}


	/**
	 * @param emblemSize
	 *            the emblemSize to set
	 */
	public void setUploadSize(int emblemSize)
	{
		this.uploadSize = emblemSize;
		uploadData = new byte[uploadSize];
	}

	/**
	 * @return the emblemSize
	 */
	public int getUploadSize()
	{
		return uploadSize;
	}

	/**
	 * @param uploadData The uploadData to set.
	 */
	public void setUploadData(byte[] uploadData)
	{
		this.uploadData = uploadData;
	}


	/**
	 * @param uploadData
	 *            the uploadData to set
	 */
	public boolean addUploadData(byte[] data)
	{
		for (byte dataByte : data)
		{
			uploadData[uploadedIndex++] = dataByte;
		}
		return (uploadData.length == uploadedIndex);
	}

	/**
	 * @return the uploadData
	 */
	public byte[] getUploadData()
	{
		return this.uploadData;
	}

	/**
	 * This method will clear out all upload data
	 */
	public void resetUploadSettings()
	{
		this.isUploading = false;
		this.uploadedIndex = 0;
	}

	/**
	 * 
	 * @param persistentState
	 */
	public void setPersistentState(PersistentState persistentState)
	{
		switch (persistentState)
		{
			case UPDATE_REQUIRED:
				if (this.persistentState == PersistentState.NEW)
					break;
			default:
				this.persistentState = persistentState;
		}
	}

	/**
	 * @return the persistentState
	 */
	public PersistentState getPersistentState()
	{
		return persistentState;
	}

}
